home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / kernel / genfun.d < prev    next >
Text File  |  1996-08-25  |  3KB  |  114 lines

  1. /*
  2.  *
  3.  *    Copyright (c) 1993-1996 Algorithms Corporation
  4.  *    3020 Liberty Hills Drive
  5.  *    Franklin, TN  37067
  6.  *
  7.  *    ALL RIGHTS RESERVED.
  8.  *
  9.  *
  10.  *
  11.  */
  12.  
  13. #include <string.h>
  14. #include "kernels.h"
  15.  
  16. public    defclass  GenericFunction  {
  17.  
  18. //#ifdef    FASTWIDE
  19.     ofun        *mc;        /*  method cache (# of classes long)  */
  20. //#endif
  21.     char        *name;
  22.     int        id;    /*  generic id  */
  23.     int        cache_idx;
  24. //    object_list    *methods;     was never accessed and causes problems with native threads
  25.     int        trace;
  26.     object        next;
  27. };
  28.  
  29. imeth    void    gInvalidObject(int argn, object arg1)
  30. {
  31.     char    buf[256];
  32.  
  33.     sprintf(buf, "\nDynace: Generic %s passed an invalid object on arg %d.\n", gName(self), argn);
  34.     if (argn != 1  &&  arg1)
  35.         if (IsaClass(arg1))
  36.             sprintf(buf+strlen(buf), "First argument to generic %s was the class %s\n", gName(self), gName(arg1));
  37.         else
  38.             sprintf(buf+strlen(buf), "First argument to generic %s was an instance of the %s class\n", gName(self), gName(ClassOf(arg1)));
  39.     gError(self, buf);
  40. }
  41.  
  42. imeth    void    gInvalidType(int argn, object arg1, object cls, object arg)
  43. {
  44.     char    buf[320];
  45.  
  46.     sprintf(buf, "\nDynace: Generic %s passed an invalid object type on arg %d.\n", gName(self), argn);
  47.     sprintf(buf+strlen(buf), "Expected an instance of %s\n", gName(cls));
  48.     sprintf(buf+strlen(buf), "Received an instance of %s\n", gName(ClassOf(arg)));
  49.     if (argn != 1  &&  arg1)
  50.         if (IsaClass(arg1))
  51.             sprintf(buf+strlen(buf), "First argument to generic %s was the class %s\n", gName(self), gName(arg1));
  52.         else
  53.             sprintf(buf+strlen(buf), "First argument to generic %s was an instance of the %s class\n", gName(self), gName(ClassOf(arg1)));
  54.     gError(self, buf);
  55. }
  56.  
  57. imeth    char    *gName()
  58. {
  59.     return name;
  60. }    
  61.  
  62. imeth    int    gTrace(int mode)
  63. {
  64.     int    pmode = trace;
  65.     trace = mode;
  66.     return pmode;
  67. }    
  68.  
  69. imeth    gCopy()
  70. {
  71.     return gShouldNotImplement(self, "gCopy/gDeepCopy");
  72. }
  73.  
  74. objrtn    GenericFunction_initialize(void)
  75. {
  76.     static    int    done = 0;
  77.  
  78.     /*  Class creation and some of the methods are initialized by
  79.         the kernel  */
  80.  
  81.     if (done)
  82.         return GenericFunction_c;
  83.  
  84.     done = 1;
  85.  
  86. /*    GenericFunction_c = gNewClass(Class, "GenericFunction",    sizeof(GenericFunction_iv_t), 0, END);    */
  87.  
  88.     iMethodFor(GenericFunction, gInvalidObject, GenericFunction_im_gInvalidObject);
  89.     iMethodFor(GenericFunction, gInvalidType, GenericFunction_im_gInvalidType);
  90.     iMethodFor(GenericFunction, gName, GenericFunction_im_gName);
  91.     iMethodFor(GenericFunction, gTrace, GenericFunction_im_gTrace);
  92.     iMethodFor(GenericFunction, gCopy, GenericFunction_im_gCopy);
  93.     iMethodFor(GenericFunction, gDeepCopy, GenericFunction_im_gCopy);
  94.     return GenericFunction_c;
  95. }
  96.  
  97. #if 0  /*  code for the benefit of dpp  */
  98.  
  99. cmeth    gNewWithStr(char *n){}
  100.  
  101. #endif
  102.  
  103. /*
  104.  *
  105.  *    Copyright (c) 1993-1996 Algorithms Corporation
  106.  *    3020 Liberty Hills Drive
  107.  *    Franklin, TN  37067
  108.  *
  109.  *    ALL RIGHTS RESERVED.
  110.  *
  111.  *
  112.  *
  113.  */
  114.